package array;

import java.util.Scanner;

/**
 * @author zhangguisong
 * @date 2022-10-24 13:55
 */
public class TwoDimensionalArrayToSparseArray {
    private int raw;
    private static  final int col = 3;
    private int value;

    /**
     * 二维数据to稀疏数组
     *
     * @author zhangguisong
     * @date 2022-10-24 13:56
     */
    public  static  int[][] TwoDimensionalToSparseArray(int[][] source, int raw, int col) {
        int length = source.length;
        System.out.println(length);
        int count = 0;
        for (int i = 0; i < raw; i++) {
            for (int j = 0; j < col; j++) {
                if (source[i][j] != 0) {
                    count++;
                }
            }
        }
        int[][] target = new int[count + 1][TwoDimensionalArrayToSparseArray.col];
        target[0][0] = raw;
        target[0][1] = col;
        target[0][2] = 0;
        int k = 1;
        for (int i = 0; i < raw; i++) {
            for (int j = 0; j < col; j++) {
                if (source[i][j] != 0) {
                    target[k][0] = i;
                    target[k][1] = j;
                    target[k][2] = source[i][j];
                    k++;
                }
            }
        }
        return target;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[][] source = new int[2][5];
        while (in.hasNextInt()) {
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 5; j++) {
                    source[i][j] = in.nextInt();
                }
            }
            int[][] result= TwoDimensionalToSparseArray(source,2,5);
            for (int i = 0; i < result.length; i++) {
                for (int j = 0; j < 3; j++) {
                    System.out.println(result[i][j]);
                }
            }
        }

    }
}
